package org.gruposp2p.proyectokarma.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Table;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.GeneratedValue;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
@Table(name="CometdMessage")
public class CometdMessage {

    public static final String ACTION_LEAVE     = "leave";
    public static final String ACTION_JOIN      = "join";
    public static final String ACTION_MESSAGE   = "message";
    public static final String ACTION_BROADCAST = "broadcast";

    @Id @GeneratedValue(strategy=IDENTITY)
    @Column(name="id", unique=true, nullable=false)
    private Long id;
    private String status;
    private String area;
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="peerFromId", nullable=false)
    private Peer peerFrom;
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="peerToId", nullable=false)
    private Peer peerTo;
    private String password;
    private String action;
    private String content;
    private String subject;
    private String channel;
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="date", nullable=false, length=23)
    private Date date;

    public CometdMessage() { }

    public CometdMessage(String area, Peer peerFrom, Peer peerTo,
                    String password, String action, String content, String subject, String channel) {
            this.area = area;
            this.peerFrom = peerFrom;
            this.peerTo = peerTo;
            this.password = password;
            this.action = action;
            this.content = content;
            this.subject = subject;
            this.channel = channel;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the status
     */
    public String getStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * @return the area
     */
    public String getArea() {
        return area;
    }

    /**
     * @param area the area to set
     */
    public void setArea(String area) {
        this.area = area;
    }

    /**
     * @return the peerFrom
     */
    public Peer getPeerFrom() {
        return peerFrom;
    }

    /**
     * @param peerFrom the peerFrom to set
     */
    public void setPeerFrom(Peer peerFrom) {
        this.peerFrom = peerFrom;
    }

    /**
     * @return the peerTo
     */
    public Peer getPeerTo() {
        return peerTo;
    }

    /**
     * @param peerTo the peerTo to set
     */
    public void setPeerTo(Peer peerTo) {
        this.peerTo = peerTo;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the action
     */
    public String getAction() {
        return action;
    }

    /**
     * @param action the action to set
     */
    public void setAction(String action) {
        this.action = action;
    }

    /**
     * @return the content
     */
    public String getContent() {
        return content;
    }

    /**
     * @param content the content to set
     */
    public void setContent(String content) {
        this.content = content;
    }

    /**
     * @return the subject
     */
    public String getSubject() {
        return subject;
    }

    /**
     * @param subject the subject to set
     */
    public void setSubject(String subject) {
        this.subject = subject;
    }

    /**
     * @return the channel
     */
    public String getChannel() {
        return channel;
    }

    /**
     * @param channel the channel to set
     */
    public void setChannel(String channel) {
        this.channel = channel;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

}
